﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hi_Baidu.Packet;
using System.Windows.Forms;
using Hi_Baidu.FileShare.Model;

namespace Hi_Baidu.Plugin
{
    /// <summary>
    ///     提供了基础的文件包处理器
    /// </summary>
    class FileSharePacketListener : IPacketListener
    {
        #region IPacketListener 成员

        public bool Accpet(InPackage pck)
        {
            return pck.GetProtocol() == Protocol.NetworkProtocol.TRANSFER_FILE;
        }

        public void PackageArrived(InPackage pck)
        {
            switch ((pck as SendFileInPackage).Command)
            {
                //发送文件请求包
                case Protocol.IN_SendFile.REQUEST_SEND_FILE:
                    RequestSendFileModel.ProcessRequestSendFile(new Hi_Baidu.FileShare.Packet.InPacket.RequestSendFilePacket(pck));
                    break;
                //拒绝文件信息包
                case Protocol.IN_SendFile.PASS_SEND_FILE:
                    RequestSendFileModel.ProcessACKPassSendFIle(new Hi_Baidu.FileShare.Packet.InPacket.PassSendFilePacket(pck));
                    break;
                //接收文件请求包
                case Protocol.IN_SendFile.ALLOW_SEND_FILE:
                    RequestSendFileModel.ProcessACKAllowSendFile(new Hi_Baidu.FileShare.Packet.InPacket.AllowSendFilePacket(pck));
                    break;
                default:
                    break;
            }
        }

        #endregion
    }
}
